﻿using SLAssetSystem;
using SLBehaviourSystem;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class BehaviourDemo : MonoBehaviour {

    public DemoAgent agent;

    public LogAgent logAgent;
    // Use this for initialization
    void Start () {
        //AssetSystem.Inst.LoadAsset<GameObject>(AssetPaths.PrefabsPath, "Agent");
        BehaviourTree tree = BehaviourSystem.Inst.CreateTree(1, agent);
        agent.Init(tree);
        //logAgent.SetTree(BehaviourSystem.Inst.CreateTree(3, logAgent));
        //BehaviourTree tree = logAgent.GetTree();

        tree.Excute();
        //InitSelector();
        //InitSquence();
    }

    //void InitSelector()
    //{
    //    BehaviourTree tree = BehaviourSystem.Inst.CreateTreeTest(3, agent);
    //    SelectorNode selectorNode = new SelectorNode();
    //    logAgent.SetTree(tree);

        
    //    tree.AddChild(selectorNode);
    //    BehaviourNodeBase logNode1 = new LogNode();
    //    BehaviourData logData1 = new BehaviourData();
    //    logData1.AddData("Log", "1");
    //    logNode1.BehaviourData = logData1;

    //    selectorNode.AddChild(logNode1);

    //    BehaviourNodeBase logNode2 = new LogNode();
    //    BehaviourData logData2 = new BehaviourData();
    //    logData2.AddData("Log", "2");
    //    logNode2.BehaviourData = logData2;

    //    selectorNode.AddChild(logNode2);

    //    BehaviourNodeBase wait = new WaitNode();
    //    BehaviourData waitData = new BehaviourData();
    //    waitData.AddData("WaitTime", "1");
    //    wait.BehaviourData = waitData;
    //    selectorNode.AddChild(wait);

    //    tree.Excute();


    //}

    void InitParallel()
    {
        //BehaviourTree tree = BehaviourSystem.Inst.CreateTreeTest(1, agent);
        //ParallelNode parallelNode = new ParallelNode();
        //tree.AddChild(parallelNode);
        //ActionNode waitTimeNode = new ActionNode();
        ////waitTimeNode.SetComponent();
        //BehaviourData waitTimeData = new BehaviourData();
        //waitTimeData.AddData(BehaviourArgsType.WaitTime, "2");
        //waitTimeNode.BehaviourData = waitTimeData;

        //parallelNode.AddChild(waitTimeNode);
        //LoopNode loopNode = new LoopNode();
        //BehaviourData loopData = new BehaviourData();
        //loopData.AddData(BehaviourArgsType.LoopCount, "3");
        //loopNode.BehaviourData = loopData;
        //ActionNode attackLogNode = new ActionNode();
        ////attackLogNode.SetComponent();
        //loopNode.AddChild(attackLogNode);
        //parallelNode.AddChild(loopNode);

        //LoopNode loopNode2 = new LoopNode();
        //BehaviourData loopData2 = new BehaviourData();
        //loopData2.AddData(BehaviourArgsType.LoopCount, "3");
        //loopNode2.BehaviourData = loopData2;
        //ActionNode attackLogNode2 = new ActionNode();
        //loopNode2.AddChild(attackLogNode2);
        //parallelNode.AddChild(loopNode2);

    }

    //void InitSquence()
    //{
    //    BehaviourTree tree = BehaviourSystem.Inst.CreateTreeTest(3, agent);
    //    logAgent.SetTree(tree);

    //    SquenceNode squenceNode = new SquenceNode();
    //    tree.AddChild(squenceNode);
    //    BehaviourNodeBase logNode1 = new LogNode();
    //    BehaviourData logData1 = new BehaviourData();
    //    logData1.AddData("Log", "1");
    //    logNode1.BehaviourData = logData1;

    //    squenceNode.AddChild(logNode1);

    //    BehaviourNodeBase logNode2 = new LogNode();
    //    BehaviourData logData2 = new BehaviourData();
    //    logData2.AddData("Log", "2");
    //    logNode2.BehaviourData = logData2;

    //    squenceNode.AddChild(logNode2);

    //    BehaviourNodeBase wait = new WaitNode();
    //    BehaviourData waitData = new BehaviourData();
    //    waitData.AddData("WaitTime", "1");
    //    wait.BehaviourData = waitData;
    //    squenceNode.AddChild(wait);

    //    //ActionNode idle = new IdleNode();
    //    //BehaviourData idleData = new BehaviourData();
    //    //idle.BehaviourData = idleData;
    //    //squenceNode.AddChild(idle);

    //    tree.Excute();
    //}


    // Update is called once per frame
    void Update () {
        BehaviourSystem.Inst.Tick();
    }
}
